using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Shop : MonoBehaviour {

	public Transform _prefShopHUD;
	
	public bool triggered;
	

	private Player _enteredPlayer;
	private ShopScript _shopGUI;
	
	public Player InShopPlayer{
		get {
			return _enteredPlayer;	
		}
	}
	
	// Use this for initialization
	void Start () {
		triggered = false;
		Transform shopHUD = (Transform) Instantiate(_prefShopHUD);
		_shopGUI = shopHUD.GetComponent<ShopScript>();
		_shopGUI.BootStrap(this);
	}
	
	void OnTriggerExit(Collider other) {
        //_shopGui.Render = false;
		_shopGUI.PopDown();
    }
	
	void OnTriggerEnter (Collider other)
	{
		//_shopGui.Render = true;
		//GameKeyListener.Instance.ActiveMenu = _shopMenu;
		
		Color color = this.renderer.material.color;
		color.a = 0.4f;//makes the shop transparent
		//color.b = 0.5f;
		this.renderer.material.color = color;
		
		//_shopHUD.ActiveShop = this;//where did this used to be?
		
		
			Player inShopPlayer = other.transform.GetComponent<Player>(); // TODO have check here to test if the transfrom can get player.
		
			inShopPlayer.inShop(this);
			_enteredPlayer = inShopPlayer;
			_shopGUI.PopUp();
			
			if (triggered == false)//makes it longer
			{
				Vector3 extend = new Vector3();
				extend = this.transform.localScale;
				extend.z ++;
				Quaternion backwards = this.transform.localRotation;
				
				Vector3 backwardsHalf = new Vector3(0f,0f,0.5f);
				backwardsHalf = backwards * backwardsHalf;
				
				this.transform.localScale = extend;
				extend = this.transform.localPosition;
				extend += backwardsHalf;
				this.transform.localPosition = extend;
					
				triggered = true;
			}
		
	}
	
	public static void chooseMaterial()
	{
		
	}
	
}
